const readline = require('readline')

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
})
rl.on('line', function (line) {
  const arr = line.split(' ')
  const k = arr.pop()
  getMax(arr, k)
})
function getMax (arr, k) {
  if (k > arr.length) return arr.sort[0]
  let count = 1
  // let max = arr[0]
  let flag = true
  while (flag) {
    if (count >= k) {
      flag = false
      break
    }
    if (arr[0] >= arr[1]) {
      // console.log('arr[0]>arr[1]', arr)
      count++
      // 将小于它的放到最后
      let spl = arr.splice(1, 1)[0]
      arr.push(spl)
      // max = arr[0]
    }
    else {
      // console.log('arr[0]<arr[1]', arr
      count = 1
      let shif = arr.shift()
      arr.push(shif)
      max = arr[0]
    }
  }

  console.log(arr[0])
}



